/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 *
 * @version 1.0
 */
package shop.controller.front.orderpay;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.RequestHolder;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.core.common.oscache.SystemManager;
import shop.core.plugins.wxmsg.WxMsgUtil;
import shop.core.plugins.wxpay.WXPay;
import shop.core.plugins.wxpay.WXPayConfigImpl;
import shop.core.plugins.wxpay.WXPayConstants;
import shop.core.plugins.wxpay.WXPayUtil;
import shop.core.util.AddressUtils;
import shop.services.front.activity.ActivityService;
import shop.services.front.activity.bean.Activity;
import shop.services.front.activityjoin.ActivityjoinService;
import shop.services.front.activityjoin.bean.Activityjoin;
import shop.services.front.balance.BalanceService;
import shop.services.front.balance.bean.Balance;
import shop.services.front.order.OrderService;
import shop.services.front.order.bean.Order;
import shop.services.front.orderdetail.OrderdetailService;
import shop.services.front.orderdetail.bean.Orderdetail;
import shop.services.front.orderpay.OrderpayService;
import shop.services.front.orderpay.bean.Orderpay;
import shop.services.front.product.ProductService;
import shop.services.front.product.bean.Product;
import shop.services.front.record.RecordService;
import shop.services.front.record.bean.Record;
import shop.services.front.seat.SeatService;
import shop.services.front.seat.bean.Seat;
import shop.services.front.spec.SpecService;
import shop.services.front.spec.bean.Spec;
import shop.services.front.store.StoreService;
import shop.services.front.store.bean.Store;
import shop.services.front.voucherhave.VoucherhaveService;
import shop.services.front.voucherhave.bean.Voucherhave;
import shop.services.manage.system.bean.User;
import shop.services.manage.system.impl.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

/**
 * @类名称：OrderpayController
 * @创建人：Wzl
 * @创建时间：2017-12-20 下午15:50:16
 * @版本号：1.0
 * @描述：订单支付
 */
@Controller
@RequestMapping("/front/orderpay/")
public class OrderpayController extends FrontBaseController<Orderpay> {
    private final static String RECORT_TYANSTYPE_CASH = "1";
    private final static String RECORT_TYANSTYPE_SUB_INORDER = "2";
    private final static String RECORT_TYANSTYPE_SUB_OUTORDER = "3";
    private final static String RECORT_TYANSTYPE_INCOME_INORDER = "4";
    private final static String RECORT_TYANSTYPE_INCOME_OUTORDER = "5";
    private final static String RECORT_TYANSTYPE_BALANCE_INORDER = "6";
    private final static String RECORT_TYANSTYPE_BALANCE_OUTORDER = "7";
    private final static String RECORT_TYANSTYPE_RECHARGE = "8";
    private final static String RECORT_TYANSTYPE_SUB_RECHARGE = "9";
    private final static String ORDER_TYPE_INSTORE = "in";
    private final static String ORDER_TYPE_OUTSTORE = "out";
    private final static String ORDER_PAYTYPE_ORDER = "order";
    private final static String ORDER_PAYTYPE_ACTIVITY = "activity";
    private final static String ORDER_PAYTYPE_BALANCE = "balance";
    private final static String ORDER_STATUS_INIT = "init";
    private final static String ORDER_STATUS_PASS = "pass";
    private final static String ORDER_STATUS_SEND = "send";
    private final static String ORDER_STATUS_FINISH = "finish";
    private final static String ORDER_STATUS_CANCEL = "cancel";
    @Resource
    private OrderpayService orderpayService;
    @Resource
    private OrderService orderService;
    @Resource
    private ProductService productService;
    @Resource
    private SpecService specService;
    @Resource
    private OrderdetailService orderdetailService;
    @Resource
    private RecordService recordService;
    @Resource
    private VoucherhaveService voucherhaveService;
    @Resource
    private UserService userService;
    @Resource
    private ActivityService activityService;
    @Resource
    private ActivityjoinService activityjoinService;
    @Resource
    private BalanceService balanceService;
    @Resource
    private SeatService seatService;
    @Resource
    private StoreService storeService;
    @Autowired
    private SystemManager systemManager;

    private WXPay wxpay;
    private WXPayConfigImpl config;

    @Override
    public Services<Orderpay> getService() {
        return orderpayService;
    }

    //活动ID
    private String activityID;
    //活动标签名称一
    private String titleOneName;
    //活动标签名称二
    private String titleTwoName;
    //充值赠送金额
    private BigDecimal sendMoney;

    /**
     * 获取预支付信息
     *
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getPrepayId", method = RequestMethod.GET)
    @ResponseBody
    public JSONResult getPrepayId(HttpSession session, Order order) throws Exception {
        activityID = order.getActivityID();
        titleOneName = order.getTitleOneName();
        titleTwoName = order.getTitleTwoName();
        sendMoney = order.getSendMoney();
        JSONResult jsonResult = new JSONResult();
        order.setStatus(ORDER_STATUS_INIT);
        String out_trade_no = UUID.randomUUID().toString().replace("-", "");
        User user = (User) session.getAttribute("userInfo");
        String orderID = "";
        if (!StringUtils.isBlank(order.getId())) {
            logger.debug("已有订单：" + order.getId());
            orderID = order.getId();
        } else {
            // 获取支付表的订单ID
            orderID = (String) getOrderID(user, order).getData();
        }
        config = WXPayConfigImpl.getInstance(systemManager);
        wxpay = new WXPay(config);
        BigDecimal orderPtotal = order.getPtotal();
        Float floatOrderPtotal = orderPtotal.floatValue() * 100;
        String total_fee = String.valueOf(floatOrderPtotal.intValue());//商品总价
        HashMap<String, String> data = new HashMap<String, String>();
        data.put("body", "味爱");//商品描述
        data.put("out_trade_no", out_trade_no);//商户订单号
        data.put("device_info", "");//设备号
        data.put("total_fee", total_fee);//标价金额
        String clientIp = AddressUtils.getIp(RequestHolder.getRequest()).split(",")[0];
        data.put("spbill_create_ip", clientIp);//终端IP
        data.put("notify_url", systemManager.getSystemSetting().getWww() + "/rest/front/orderpay/notify");//通知地址
        data.put("trade_type", "JSAPI");//交易类型
        data.put("product_id", UUID.randomUUID().toString().replace("-", ""));//商品ID
        data.put("openid", session.getAttribute("userOpenId").toString());//openID
        logger.debug("data数据信息：" + data);

        try {
            Map<String, String> r = wxpay.unifiedOrder(data);
            logger.debug("获得预支付信息为：" + r.get("return_msg") + ",获得返回状态码为：" + r.get("return_code"));
            //回传页面参数
            Map<String, String> reqData = new HashMap<String, String>();
            reqData.put("appId", config.getAppID());//公众账号ID
            logger.debug("公众账号ID" + config.getAppID());
            reqData.put("timeStamp", String.valueOf(new Date().getTime() / 1000));//生成签名的时间戳
            reqData.put("nonceStr", r.get("nonce_str"));//随机字符串
            reqData.put("signType", "MD5");//签名类型
            reqData.put("package", "prepay_id=" + r.get("prepay_id"));//预支付交易会话标识
            String paySign = WXPayUtil.generateSignature(reqData, config.getKey(), WXPayConstants.SignType.MD5);//获取微信支付签名
            reqData.put("paySign", paySign);//签名
            logger.debug("回传页面参数填写完成：" + reqData);
            //插入订单支付表
            Orderpay orderpay = new Orderpay();
            orderpay.setOrderID(orderID);
            Orderpay anOrderpay = orderpayService.selectOne(orderpay);
            if (anOrderpay != null) {
                anOrderpay.setPrepayId(r.get("prepay_id"));//赋值,预支付ID
                anOrderpay.setOutTradeNo(out_trade_no);//赋值,商户订单号
                getService().update(anOrderpay);//更新订单支付信息
                jsonResult.setData(reqData);//回传页面参数
                return jsonResult;
            } else {
                orderpay.setPayStatus("0");//赋值,支付状态
                orderpay.setPrepayId(r.get("prepay_id"));//赋值,预支付ID
                orderpay.setPayType(data.get("trade_type"));//赋值,交易类型
                orderpay.setPayAmount(order.getPtotal());//赋值,支付金额
                orderpay.setOutTradeNo(out_trade_no);//赋值,商户订单号
                orderpay.setProductBody(data.get("body"));//赋值,商品描述
                getService().insert(orderpay);//插入订单支付表
                jsonResult.setData(reqData);//回传页面参数
                return jsonResult;
            }
        } catch (Exception e) {
            logger.debug("打印错误日志：");
            e.printStackTrace();
            jsonResult.setSuccess(false);
            return jsonResult;
        }
    }

    /**
     * 微信支付回调接口
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "notify", produces = "application/xml;charset=UTF-8")
    @ResponseBody
    public String payNotifyUrl(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DecimalFormat df = new DecimalFormat("######0.00");//设定double格式，保留两位小数
        BufferedReader reader = request.getReader();//读取输入字符
        String line = "";
        String xmlString = null;
        StringBuffer inputString = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            inputString.append(line);
        }
        xmlString = inputString.toString();
        request.getReader().close();//关闭输入流
        Map<String, String> receiveData = WXPayUtil.xmlToMap(xmlString);
        logger.debug("收到支付回调结果:" + receiveData);
        String out_trade_no = receiveData.get("out_trade_no");
        Orderpay orderpay = new Orderpay();
        orderpay.setOutTradeNo(out_trade_no);//赋值,商户订单号
        orderpay = getService().selectOne(orderpay);//查询支付记录
        logger.debug("查询本地支付记录：" + orderpay);
        String orderID = orderpay.getOrderID();
        String returnCode = receiveData.get("return_code");//返回状态码
        HashMap<String, String> data = new HashMap<String, String>();
        String returnString = "";
        //模板消息推送
        Order order = new Order();
        order.setId(orderID);
        order = orderService.selectOne(order);
        User user = new User();
        user.setId(order.getUserID());
        user = userService.selectOne(user);
        Store store = new Store();
        store.setId(order.getStoreID());
        store = storeService.selectOne(store);
        Activity activity=new Activity();
        activity.setId(activityID);
        activity=activityService.selectOne(activity);
        if (returnCode.equals("SUCCESS")) {//判断交易是否成功
            returnString = updateData(receiveData, data, orderpay, returnString, orderID);
            if(ORDER_PAYTYPE_ORDER.equals(order.getPayType())){
                //付款成功模板消息推送
                Map<String, String> msgParam = new HashMap<>();
                if (ORDER_TYPE_INSTORE.equals(order.getType())) {
                    msgParam.put("first", "您好，您的线下订单已付款成功！状态已完成。");
                } else {
                    msgParam.put("first", "您好，您的外卖订单已付款成功！状态待送达。");
                }
                msgParam.put("keyword1", order.getId());
                msgParam.put("keyword2", order.getPtotal().toString());
                msgParam.put("keyword3", store.getName());
                msgParam.put("keyword4", order.getUpdateTime());
                msgParam.put("remark", "感谢您的惠顾！");
                WxMsgUtil.sendPayStatusMsg(msgParam, systemManager, user.getOpenID(), order);
            }else if(ORDER_PAYTYPE_ACTIVITY.equals(order.getPayType())){
                logger.debug("报名活动成功消息推送: "+order.getPayType());
                //报名活动成功消息推送
                Map<String, String> msgParam = new HashMap<>();
                msgParam.put("first", "您好，恭喜您活动报名成功！");
                msgParam.put("keyword1", activity.getStartDate());
                msgParam.put("keyword2", activity.getAddress());
                msgParam.put("remark", "请及时参加活动！");
                WxMsgUtil.sendActivityJoinStatusMsg(msgParam, systemManager, user.getOpenID(), activity);
            }else{}
        } else {
            data.put("return_code", "FAIL");
            data.put("return_msg", "支付失败");
            returnString = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
                    + "<return_msg><![CDATA[支付失败]]></return_msg>" + "</xml> ";
        }
        logger.debug("返回支付状态消息给微信：" + returnString);
        return returnString;
    }


    /**
     * 获取订单ID
     *
     * @param order
     * @return
     * @throws Exception
     */
    private JSONResult getOrderID(User user, Order order) throws Exception {
        String orderID = "";
        String productName="";//模板消息所需信息
        // 获取支付表的订单ID
        if (user == null)
            return JSONResult.error("您还未进行授权，无法购物");//判断用户是否授权登陆
        logger.debug("插入订单：");
        if ("order".equals(order.getPayType())) {
            String[] productIDs = order.getProductIDs().split(",");
            String[] specIDs = order.getSpecIDs().split(";");
            String[] productAmount = order.getProductAmount().split(",");
            for (int i = 0; i < productIDs.length; i++) {
                Spec spec = new Spec();
                spec.setProductID(productIDs[i]);
                spec.setCombination(specIDs[i]);
                spec = specService.selectOne(spec);//查询该件商品库存
                Product productInfo = new Product();
                productInfo.setId(productIDs[i]);
                productInfo = productService.selectOne(productInfo);//查询该件商品
                if(i==productIDs.length-1){
                    productName+=productInfo.getName();
                }else{
                    productName+=productInfo.getName()+",";
                }
                productName=productInfo.getName();
                if (((spec.getStock() - Integer.parseInt(productAmount[i])) < 0))
                    return JSONResult.error(productInfo.getName() + "商品库存不足，请重新下单!");
            }
        }
        order.setUserID(user.getId());
        orderID = String.valueOf(orderService.insert(order));
        //待付款订单模板消息推送
        if(ORDER_PAYTYPE_ORDER.equals(order.getPayType())){
            Store store = new Store();
            store.setId(order.getStoreID());
            store = storeService.selectOne(store);
            Order orderInfo=new Order();
            orderInfo.setId(orderID);
            orderInfo=orderService.selectOne(orderInfo);
            Map<String, String> msgParam = new HashMap<>();
            msgParam.put("first", "您好，您有个订单等待付款！");
            msgParam.put("keyword1", store.getName());
            msgParam.put("keyword2", orderInfo.getPtotal().toString());
            msgParam.put("keyword3", orderInfo.getCreateTime());
            msgParam.put("remark", "请及时支付！");
            WxMsgUtil.sendUnPayStatusMsg(msgParam, systemManager, user.getOpenID(), orderInfo);
        }
        JSONResult jsonResult = new JSONResult();
        jsonResult.setData(orderID);
        return jsonResult;
    }

    /**
     * 支付数据维护
     *
     * @param
     * @return
     * @throws Exception
     */
    private String updateData(Map<String, String> receiveData, HashMap<String, String> data, Orderpay orderpay, String returnString, String orderID) throws Exception {
        Order order = orderService.selectById(orderID);
        User loginUser = new User();
        loginUser.setId(order.getUserID());
        loginUser = userService.selectOne(loginUser);
        if (order.getStatus().equals(ORDER_STATUS_INIT) && ORDER_PAYTYPE_ORDER.equals(order.getPayType())) {
            Orderdetail orderdetail = new Orderdetail();
            orderdetail.setOrderID(orderID);
            //查询订单详情列表
            List<Orderdetail> orderdetailList = orderdetailService.selectList(orderdetail);
            //遍历订单详情
            for (Orderdetail anOrdedetail : orderdetailList) {
                //查询商品信息
                Product product = new Product();
                product.setId(anOrdedetail.getProductID());
                product = productService.selectOne(product);
                //更新平台商品库存
                Spec spec = new Spec();
                spec.setProductID(anOrdedetail.getProductID());
                spec.setCombination(anOrdedetail.getSpecInfo());
                spec = specService.selectOne(spec);
                spec.setStock(spec.getStock() - anOrdedetail.getNumber());
                specService.update(spec);
                //更新平台商品销售量
                product.setSellcount(product.getSellcount() + anOrdedetail.getNumber());
                productService.update(product);
            }
            //支付数据维护(购买商品)
            updateOrderData(loginUser, order);
        } else if (order.getStatus().equals(ORDER_STATUS_INIT) && ORDER_PAYTYPE_ACTIVITY.equals(order.getPayType())) {
            //支付数据维护(活动报名)
            updateActivityData(loginUser, order);
        } else if (order.getStatus().equals(ORDER_STATUS_INIT) && ORDER_PAYTYPE_BALANCE.equals(order.getPayType())) {
            //支付数据维护(余额充值)
            updateBalanceData(loginUser, order);
        } else {
        }
        // 更新订单状态
        logger.debug("更新订单状态");
        if (ORDER_TYPE_OUTSTORE.equals(order.getType()) && ORDER_PAYTYPE_ORDER.equals(order.getPayType())) {
            order.setStatus(ORDER_STATUS_PASS);
        } else {
            order.setStatus(ORDER_STATUS_FINISH);
            //解绑座位号
            Seat seat = new Seat();
            seat.setId(order.getSeatNumber());
            seat.setStatus("unBind");
            seat.setOrderID("0");
            seatService.update(seat);
            order.setSeatNumber("0");
        }
        orderService.update(order);
        //更新本地订单支付表信息
        logger.debug("更新本地订单支付表信息：" + orderpay);
        orderpay.setTransactionId(receiveData.get("transaction_id"));
        orderpay.setPayStatus("1");
        getService().update(orderpay);
        data.put("return_code", "SUCCESS");
        data.put("return_msg", "OK");
        returnString = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>"
                + "<return_msg><![CDATA[OK]]></return_msg>"
                + "</xml> ";
        return returnString;
    }

    /**
     * 支付数据维护(购买商品)
     *
     * @param
     * @throws Exception
     */
    private void updateOrderData(User loginUser, Order order) throws Exception {
        //更新买家个人数据
        User buyer = new User();
        buyer.setId(order.getUserID());
        buyer = userService.selectOne(buyer);
        buyer.setIncome(buyer.getIncome().subtract(order.getIncome()));
        buyer.setBalance(buyer.getBalance().subtract(order.getBalance()));
        BigDecimal score = buyer.getScore().add(order.getOtotal());
        logger.debug("用户积分" + score);
        buyer.setScore(score);
        userService.update(buyer);
        if (!"0".equals(order.getVoucherID())) {
            Voucherhave voucherhave = new Voucherhave();
            voucherhave.setUserID(buyer.getId());
            voucherhave.setVoucherID(order.getVoucherID());
            voucherhave = voucherhaveService.selectOne(voucherhave);
            voucherhave.setAmount(voucherhave.getAmount() - 1);
            voucherhaveService.update(voucherhave);//更新用户礼卷数量
            if (voucherhave.getAmount() == 0)
                voucherhaveService.delete(voucherhave);
        }
        //买家交易记录
        Record record = new Record();
        record.setUserID(buyer.getId());
        record.setTransID(order.getId());
        if (ORDER_TYPE_INSTORE.equals(order.getType()) && order.getIncome().compareTo(new BigDecimal(0)) != 0) {
            record.setTransType(RECORT_TYANSTYPE_INCOME_INORDER);
            record.setMoney(order.getIncome());
            recordService.insert(record);
        }
        if (ORDER_TYPE_INSTORE.equals(order.getType()) && order.getBalance().compareTo(new BigDecimal(0)) != 0) {
            record.setTransType(RECORT_TYANSTYPE_BALANCE_INORDER);
            record.setMoney(order.getBalance());
            recordService.insert(record);
        }
        if (ORDER_TYPE_OUTSTORE.equals(order.getType()) && order.getIncome().compareTo(new BigDecimal(0)) != 0) {
            record.setTransType(RECORT_TYANSTYPE_INCOME_OUTORDER);
            record.setMoney(order.getIncome());
            recordService.insert(record);
        }
        if (ORDER_TYPE_OUTSTORE.equals(order.getType()) && order.getBalance().compareTo(new BigDecimal(0)) != 0) {
            record.setTransType(RECORT_TYANSTYPE_BALANCE_OUTORDER);
            record.setMoney(order.getBalance());
            recordService.insert(record);
        }
        //买家上级数据更新
        if (!"0".equals(loginUser.getPid())) {
            //上级返利
            User supUser = new User();
            supUser.setId(loginUser.getPid());
            supUser = userService.selectOne(supUser);
            BigDecimal brokerage = order.getOtotal().multiply(new BigDecimal("0.2"));
            brokerage = brokerage.setScale(2, BigDecimal.ROUND_HALF_UP);
            logger.debug("返利金额" + brokerage);
            BigDecimal income = supUser.getIncome().add(brokerage);
            logger.debug("用户收益" + income);
            supUser.setIncome(income);
            userService.update(supUser);
            //上级交易记录
            Record recordInfo = new Record();
            recordInfo.setUserID(supUser.getId());
            if (ORDER_TYPE_INSTORE.equals(order.getType())) {
                recordInfo.setTransType(RECORT_TYANSTYPE_SUB_INORDER);
            } else {
                recordInfo.setTransType(RECORT_TYANSTYPE_SUB_OUTORDER);
            }
            recordInfo.setTransID(order.getId());
            recordInfo.setMoney(order.getOtotal().multiply(new BigDecimal("0.2")));
            recordService.insert(recordInfo);
            //收益到账模板消息推送
            recordInfo=recordService.selectOne(recordInfo);
            Map<String, String> msgParam = new HashMap<>();
            msgParam.put("first", "收益到账通知：");
            msgParam.put("keyword1", recordInfo.getMoney().toString());
            msgParam.put("keyword2", "您的团队成员消费");
            msgParam.put("keyword3", recordInfo.getCreateTime());
            msgParam.put("remark", "点击查看详情");
            WxMsgUtil.sendIncomeMsg(msgParam, systemManager, supUser.getOpenID());
        }
    }

    /**
     * 支付数据维护(活动报名)
     *
     * @param
     * @throws Exception
     */
    private void updateActivityData(User loginUser, Order order) throws Exception {
        //插入活动报名记录
        Activityjoin activityjoin = new Activityjoin();
        activityjoin.setUserID(loginUser.getId());
        activityjoin.setActivityID(activityID);
        activityjoin.setTitleOneName(titleOneName);
        activityjoin.setTitleTwoName(titleTwoName);
        Activityjoin activityjoinInfo = activityjoinService.selectOne(activityjoin);
        if (activityjoinInfo == null) {
            activityjoinService.insert(activityjoin);
        }
        //更新活动参与人数
        Activity activity = new Activity();
        activity.setId(activityID);
        activity = activityService.selectOne(activity);
        activity.setAmount(activity.getAmount() + 1);
        activityService.update(activity);
    }

    /**
     * 支付数据维护(余额充值)
     *
     * @param
     * @throws Exception
     */
    private void updateBalanceData(User loginUser, Order order) throws Exception {
        //生成充值记录
        Balance balance = new Balance();
        balance.setUserID(loginUser.getId());
        balance.setMoney(order.getPtotal());
        balance.setSendMoney(sendMoney);
        balanceService.insert(balance);
        //更新用户余额
        loginUser.setBalance(loginUser.getBalance().add(sendMoney));
        userService.update(loginUser);
        //更新上级用户信息
        if(!"0".equals(order.getPid())){
            User supUser = new User();
            supUser.setId(order.getPid());
            supUser = userService.selectOne(supUser);
            BigDecimal income = supUser.getIncome().add(new BigDecimal("100"));
            supUser.setIncome(income);
            userService.update(supUser);//更新上级收益
            Record record = new Record();
            record.setUserID(supUser.getId());
            record.setTransType(RECORT_TYANSTYPE_SUB_RECHARGE);
            record.setTransID(order.getId());
            record.setMoney(new BigDecimal("100"));
            recordService.insert(record);//生成交易记录
            //收益到账模板消息推送
            record=recordService.selectOne(record);
            Map<String, String> msgParam = new HashMap<>();
            msgParam.put("first", "收益到账通知：");
            msgParam.put("keyword1", record.getMoney().toString());
            msgParam.put("keyword2", "下级充值");
            msgParam.put("keyword3", record.getCreateTime());
            msgParam.put("remark", "点击查看详情");
            WxMsgUtil.sendIncomeMsg(msgParam, systemManager, supUser.getOpenID());
        }
        //生成交易记录
        Record record = new Record();
        record.setUserID(loginUser.getId());
        record.setTransType(RECORT_TYANSTYPE_RECHARGE);
        record.setTransID(order.getId());
        record.setMoney(order.getPtotal());
        recordService.insert(record);
    }

    @Override
    public JSONResult deleteJson(HttpServletRequest request, Orderpay orderpay) throws Exception {
        return null;
    }
}
